//
//  Picture.swift
//  Fancyswap
//
//  Created by Jonathan Muschalle on 2015-03-07.
//  Copyright (c) 2015 Jonathan Muschalle. All rights reserved.
//

import UIKit

class Picture : PictureToAdd {
    
    private var fullPath:String
    
    private var imageObject:UIImage
    
    private var isDummy = false
    
    private var uniqueName = "not-set"
    
    private var isUploaded = false
    
    private var uploadProgress:Float = 0
    
    init(path: String) {
        fullPath = path
        let url = NSURL(string: path)
        let imageData = NSData(contentsOfURL: url!)
        let image = UIImage(data: imageData!)!
        imageObject = image
    }
    
    init() {
        isDummy = true
        imageObject = UIImage()
        fullPath = "no-path"
    }
    
    init(image: UIImage) {
        fullPath = "no-path"
        imageObject = image
        let date = NSDate()
        let uniqueNameTimeStamp = date.timeIntervalSince1970
        uniqueName = "\(uniqueNameTimeStamp)"
    }
    
    func getUniqueName() -> String {
        return uniqueName
    }
    
    class func createDummyPicture() -> PictureToAdd {
        return Picture()
    }
    
    class func createPictureFromUrl(url: String) -> PictureToAdd {
        return Picture(path: url)
    }
    
    class func createPictureFromImageObject(picture: UIImage) -> PictureToAdd {
        return Picture(image: picture)
    }
    
    func isDummyPicture() -> Bool {
        return isDummy
    }
    
    func getPath() -> String {
        return fullPath
    }
    
    func getImageObject() -> UIImage {
        return imageObject
    }
    
    func pictureDidUpload() {
        isUploaded = true
    }
    
    func isPictureUploaded() -> Bool {
        return isUploaded
    }
    
    func updateUploadProgress(progress: Float) {
        uploadProgress = progress
    }
    
    func getUploadProgress() -> Float {
        return uploadProgress
    }
    
}
